package com.miniot.base.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.miniot.base.dto.*;
import com.miniot.base.entity.BoundManage;
import com.miniot.base.entity.Brand;
import com.miniot.base.entity.Devotion;
import com.miniot.base.entity.WarehouseManage;
import com.miniot.base.mapper.BoundManageMapper;
import com.miniot.base.mapper.DevotionMapper;
import com.miniot.base.service.*;
import com.miniot.base.vo.CountVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
@AllArgsConstructor
@Slf4j
public class VsualizationServiceImpl implements VsualizationService {
    private final WarehouseManageService warehouseManageService;
    private final BoundManageService boundManageService;
    private final TypeTwoService typeTwoService;
    private final BrandService brandService;
    private final DevotionMapper devotionMapper;
    private final BoundManageMapper boundManageMapper;
    @Override
    public CountVO countNum() {
        int wareHouse = warehouseManageService.count();
        int ck = boundManageService.count(new LambdaQueryWrapper<BoundManage>().like(BoundManage::getOrderNum, "ck"));
        int rk = boundManageService.count(new LambdaQueryWrapper<BoundManage>().like(BoundManage::getOrderNum, "rk"));
        int count = typeTwoService.count();
        return  new CountVO(wareHouse,count, rk, ck);
    }

    @Override
    public List<WarehouseManageDTO> getWarehouseManage() {
        List<WarehouseManage> list = warehouseManageService.list(new LambdaQueryWrapper<WarehouseManage>().select(WarehouseManage::getWarehouseName, WarehouseManage::getWarehouseAddress));
        return list.stream().map(m->{
            WarehouseManageDTO warehouseManageDTO = new WarehouseManageDTO();
            BeanUtil.copyProperties(m,warehouseManageDTO);
            return warehouseManageDTO;
        }).collect(Collectors.toList());
    }
    @Override
    public List<GetLodoDTO> getLogo() {
        List<Brand> list = brandService.list(new LambdaQueryWrapper<Brand>()
                .select(Brand::getBrandName, Brand::getBrandLogo));
        return list.stream().map(m -> {
            GetLodoDTO getLodoVO = new GetLodoDTO();
            BeanUtil.copyProperties(m, getLodoVO);
            return getLodoVO;
        }).collect(Collectors.toList());
    }
    @Override
    public List<GetTotalDTO> getTotal() {
        return devotionMapper.getTotal();
    }
    @Override
    public List<GetDetailDTO> getDetail() {
        return boundManageMapper.getDetail();
    }

    @Override
    public List<BoundManageForDTO> geBoundManageDetail() {
        List<BoundManage> list = boundManageService.list();
        return list.stream().map(m -> {
            BoundManageForDTO boundManageForDTO = new BoundManageForDTO();
            BeanUtil.copyProperties(m, boundManageForDTO);
            return boundManageForDTO;
        }).collect(Collectors.toList());
    }

    @Override
    public List<DevotionDTO> getDevotion() {
        List<Devotion> devotions = devotionMapper.selectList(null);
        return devotions.stream().map(m -> {
            DevotionDTO devotionDTO = new DevotionDTO();
            BeanUtil.copyProperties(m,devotionDTO);
            return devotionDTO;
        }).collect(Collectors.toList());
    }

}
